package com.example.demo.mapper;

import com.example.demo.entity.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @program: demo
 * @description: role
 * @author: Zwill
 * @create: 2019-12-25 15:33
 **/

@Mapper
@Repository
public interface RoleMapper {
    /*查询所有角色名称*/
    @Select("select rolename from role")
    List<String> findAllRoleNames();

    /*插入角色*/
    @Select("insert into role(id,rolename,remarks) values(#{id},#{rolename},#{remarks})")
    int insertRole(Role role);

    /*查找角色名下的角色数*/
    @Select("select count(*) from role,usermsg,userrole where usermsg.uid=userrole.uid and role.id=userrole.roleid and rolename=#{rolename}")
    int findRoleNums(String rolename);

    /*删除角色*/
    @Delete("delete from role where rolename = #{rolename}")
    int DeleteRole(String rolename);

    /*角色迷糊查询*/
    @Select("select * from role where rolename like '%${rolename}%'")
    List<Role> roleFuzzyQueryByName(String rolename);

    /*显示角色列表*/
    @Select("select rolename,count(*) as nums from role,usermsg,userrole where usermsg.uid=userrole.uid and role.id=userrole.roleid GROUP BY role.rolename")
    List<Role> showRoleAndNums();

    /*查询所有角色信息*/
    @Select("select * from role")
    List<Role> selectRole();

    /*修改用户信息*/
    @Update("update role set rolename=#{rolename},remarks=#{remarks} where id = #{id}")
    int updateRole(Role role);
}
